using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Wrath.Windows.Forms;
using Wrath.Xml;
using Wrath.Xml.Objects;
using Wrath.Xml.Objects.Controls;

namespace Wrath.RuleForge.Windowing
{
    public partial class WindowClassEditor : DockContent, Interfaces.ICanUndo, Interfaces.ICanSave
    {
        private Element sourceElement;
        private WindowClass windowClass;

        public WindowClassEditor(Element windowClassElement)
        {
            InitializeComponent();

            sourceElement = windowClassElement;

            windowClass = new WindowClass(windowClassElement);            

            this.TabText = windowClass.Name;
            this.panelBackground.BackgroundImage = CurrentRuleSet.GetFrameImage(windowClass.Frame);

            foreach (WindowControl control in windowClass.SheetData.Controls)
            {
                if (control is GenericControl)
                {
                    GenericControlComponent component = new GenericControlComponent((GenericControl)control, windowClass.SheetData.Controls);
                    this.panelAutoScroll.Controls.Add((Control)component);
                }
            }
        }

        #region ICanUndo Members

        public bool UndoEnabled
        {
            get { return true; }
        }

        public void Undo()
        {
            // TODO: Implement Undo
        }

        #endregion

        #region ICanSave Members

        public void Save()
        {
            // TODO: Implement Save - propogate changes to sourceElement.
        }

        #endregion

        private void ContentPanel_BackgroundImageChanged(object sender, EventArgs e)
        {
            if (toolStripContainer1.ContentPanel.BackgroundImage != null)
            {
                toolStripContainer1.ContentPanel.Width = toolStripContainer1.ContentPanel.BackgroundImage.Width;
                toolStripContainer1.ContentPanel.Height = toolStripContainer1.ContentPanel.BackgroundImage.Height;
            }
        }
    }
}